<template>
  <div class="panel-phone">
    <el-form :rules="rules" :model="phone" ref="elFormRef">
      <el-form-item label="手机号" size="small" prop="phoneNum">
        <el-input
          v-model="phone.phoneNum"
          type="number"
          maxlength="11"
        ></el-input>
      </el-form-item>
      <el-form-item label="验证码" size="small" prop="verifyCode">
        <div class="codeBox">
          <el-input
            v-model="phone.verifyCode"
            type="number"
            maxlength="6"
            class="codeInput"
          ></el-input>
          <el-button type="primary">获取验证码</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue';
import { useStore } from 'vuex';
import { ElForm } from 'element-plus';

import { rules } from '../config/phone-config';

export default defineComponent({
  setup() {
    const phone = reactive({
      phoneNum: '',
      verifyCode: ''
    });

    const store = useStore();
    const elFormRef = ref<InstanceType<typeof ElForm>>();

    const phoneLoginAction = () => {
      elFormRef.value?.validate((valid) => {
        if (valid) {
          store.dispatch('loginModule/phoneLoginAction');

          console.log('phoneLoginAction');
        }
      });
    };

    return {
      phone,
      rules,
      phoneLoginAction,
      elFormRef
    };
  }
});
</script>

<style scoped lang="less">
// 下面是取出input表单的上下按键
:deep(input::-webkit-outer-spin-button),
:deep(input::-webkit-inner-spin-button) {
  -webkit-appearance: none !important;
}

:deep(input[type='number']) {
  -moz-appearance: textfield !important;
}
/* /deep/ input::-webkit-outer-spin-button,
/deep/ input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/ input[type='number'] {
  -moz-appearance: textfield !important;
} */

.codeBox {
  display: flex;
  justify-content: space-between;
}
.codeInput {
  width: 50%;
}
</style>
